load("@rules_cc//cc:defs.bzl", "cc_library")

licenses(["notice"])  # BSD 3-Clause

# Do not support cuda for now.
FLANN_CUDA_HDRS = [
    "src/cpp/flann/algorithms/kdtree_cuda_3d_index.h",
    "src/cpp/flann/algorithms/kdtree_cuda_builder.h",
    "src/cpp/flann/util/cutil_math.h",
]

cc_library(
    name = "flann_cpp",
    srcs = ["src/cpp/flann/flann_cpp.cpp"],
    hdrs = glob(
        [
            "src/cpp/flann/*.h",
            "src/cpp/flann/*.hpp",
            "src/cpp/flann/algorithms/*.h",
            "src/cpp/flann/nn/*.h",
            "src/cpp/flann/util/*.h",
        ],
        exclude = [
            "src/cpp/flann/algorithms/center_chooser.h",
            "src/cpp/flann/algorithms/hierarchical_clustering_index.h",
            "src/cpp/flann/algorithms/kmeans_index.h",
            "src/cpp/flann/nn/simplex_downhill.h",
            "src/cpp/flann/util/allocator.h",
            "src/cpp/flann/util/dynamic_bitset.h",
            "src/cpp/flann/util/lsh_table.h",
            "src/cpp/flann/util/serialization.h",
        ] + FLANN_CUDA_HDRS,
    ),
    features = [
        "parse_headers",
    ],
    includes = ["src/cpp"],
    textual_hdrs = [
        "src/cpp/flann/algorithms/center_chooser.h",
        "src/cpp/flann/algorithms/hierarchical_clustering_index.h",
        "src/cpp/flann/algorithms/kmeans_index.h",
        "src/cpp/flann/nn/simplex_downhill.h",
        "src/cpp/flann/util/allocator.h",
        "src/cpp/flann/util/dynamic_bitset.h",
        "src/cpp/flann/util/lsh_table.h",
        "src/cpp/flann/util/serialization.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "@lz4",
        "@lz4//:lz4_hc",
    ],
)

cc_library(
    name = "flann_c",
    srcs = ["src/cpp/flann/flann.cpp"],
    visibility = ["//visibility:public"],
    deps = [":flann_cpp"],
)
